package com.liuyanban.action.forum;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.liuyanban.action.base.BaseAction;
import com.liuyanban.domain.forum.Forumliuyan;
import com.liuyanban.domain.user.User;
import com.liuyanban.service.forum.ForumliuyanService;
import com.liuyanban.utils.DateUtil;
import com.opensymphony.xwork2.ActionContext;

@Controller("forumliuyanAction")
@Scope("prototype")
public class ForumliuyanAction extends BaseAction<Forumliuyan> {
	@Resource(name = "forumliuyanService")
	private ForumliuyanService forumliuyanService;

	public String addUI() {
		ActionContext.getContext().put("forumid", this.getModel().getForumid());
		return addUI;
	}

	public String add() {
		Forumliuyan forumliuyan = new Forumliuyan();
		User user = (User) ActionContext.getContext().getSession().get("user");
		BeanUtils.copyProperties(this.getModel(), forumliuyan);
		forumliuyan.setLiuyantime(DateUtil.formatDateByFormat(new Date(),
				DateUtil.DATETIME_FORMAT));
		forumliuyan.setUserid(user.getUserid());
		this.forumliuyanService.saveEntry(forumliuyan);
		return action2action;
	}
}
